home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Code Samples / autofind / source / mapwin.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  2.1 KB  |  82 lines  |  [TEXT/ttxt]

  1. ---<<<
  2. in module Autofinder
  3.  
  4. class DetailWindow (Window)
  5. instance variables
  6.     media
  7.     parentDoc
  8. end
  9.  
  10. method init self {class DetailWindow} #rest args #key media: parentDoc: ->
  11. (
  12.     apply nextMethod self type:@palette args
  13.     self.media := media
  14.     self.parentDoc := parentDoc
  15.     
  16.     local backgrnd := media["Detail Background"]
  17.     -- Due to Win '95 bug, window ad to be adjusted
  18.     backgrnd.x := 1; backgrnd.y := 1
  19.     append self backgrnd
  20.     
  21.     self
  22. )
  23.  
  24. method printWindow self {class DetailWindow} -> 
  25. (
  26.     local surface, scaleFactor, myTransform, oldRate
  27.  
  28.     -- Suspend thread swapping so we can guarantee that the 
  29.     -- contents of the Window don't change
  30.     threadCriticalUp()
  31.     
  32.     -- Create a PrinterSurface
  33.     surface := new PrinterSurface
  34.     
  35.     -- We calculate the ratio of our width and height to
  36.     -- that of the Printer.  The minimum of the two ratios 
  37.     -- is what we'll use to scale our bitmap.
  38.     scaleFactor := min (surface.boundary.width / self.boundary.width)  \
  39.                        (surface.boundary.height / self.boundary.height)
  40.  
  41.     -- Create a transformation matrix that represents the scaling
  42.     myTransform := mutableCopy identityMatrix
  43.     scale myTransform scaleFactor scaleFactor
  44.     
  45.     -- Display the printer dialog box and see if we should continue
  46.     if (printerDialog surface) do (
  47.          -- Stop the window's clock so we know nothing will change
  48.         oldRate := self.clock.rate
  49.         self.clock.rate := 0
  50.  
  51.       -- Transfer the window's offscreen representation
  52.       -- to the PrinterSurface with appropriate scaling
  53.       transfer surface (snapshot self undefined) \
  54.           surface.boundary myTransform
  55.           
  56.       -- Restart the window's clock
  57.       self.clock.rate := oldRate
  58.       
  59.           -- Flush the document
  60.         flushDocument surface
  61.     )
  62.  
  63.     -- Restart thread swapping
  64.     threadCriticalDown()
  65. )
  66.  
  67. -- Specialize the hide method of the palette window to purge objects.
  68. method hide self {class DetailWindow} ->
  69. (
  70.     nextMethod self
  71.     bringToFront self.parentDoc.presentedBy
  72.  
  73.     makePurgeable self.media["Detail Background"]
  74.     emptyout self
  75.     
  76.     leaveScene self.parentDoc.detailDocument
  77.     self.parentDoc.detailDocument := undefined
  78. )
  79.  
  80. "Compiled mapwin.sx"
  81. --->>>
  82.